Page({
  data: {
    houseId: '',
    houseInfo: null,
    // 轮播图数据
    imageList: [],
    // 房屋配置
    facilities: [],
    // 租约状态
    contractInfo: null,
    billInfo: null,
    notices: []
  },

  onLoad(options) {
    const { id } = options
    this.setData({ houseId: id })
    this.getHouseDetail()
    this.getContractInfo()
    this.getBillInfo()
    this.getNotices()
  },

  // 获取房源详情
  getHouseDetail() {
    // 模拟数据，实际项目中应该调用API
    this.setData({
      houseInfo: {
        id: this.data.houseId,
        title: '阳光小区 2室1厅',
        area: 89,
        price: 2800,
        type: '2室1厅',
        address: '武汉市青山区和平大道',
        floor: '18/33层',
        orientation: '南北通透',
        decoration: '精装修',
        description: '房屋配套设施齐全，采光好，通风良好，交通便利。',
        // 添加多张图片
        images: [
          '/assets/images/house1.jpg',
          '/assets/images/house2.jpg',
          '/assets/images/house3.jpg',
          '/assets/images/house4.jpg'
        ]
      },
      imageList: [
        '/assets/images/house1.jpg',
        '/assets/images/house2.jpg',
        '/assets/images/house3.jpg',
        '/assets/images/house4.jpg'
      ],
      facilities: [
        { name: '空调', icon: '/assets/icons/ac.png' },
        { name: '热水器', icon: '/assets/icons/heater.png' },
        { name: '洗衣机', icon: '/assets/icons/washer.png' },
        { name: '冰箱', icon: '/assets/icons/fridge.png' },
        { name: '电视', icon: '/assets/icons/tv.png' },
        { name: '宽带', icon: '/assets/icons/wifi.png' },
        { name: '衣柜', icon: '/assets/icons/wardrobe.png' },
        { name: '床', icon: '/assets/icons/bed.png' }
      ]
    })
  },

  // 预览图片
  onPreviewImage(e) {
    const current = e.currentTarget.dataset.current
    wx.previewImage({
      current,
      urls: this.data.imageList
    })
  },

  // 预约看房
  onBooking() {
    wx.showToast({
      title: '预约功能开发中',
      icon: 'none'
    })
  },

  // 获取合同信息
  getContractInfo() {
    // TODO: 调用合同API
    this.setData({
      contractInfo: {
        id: 'CT2024001',
        status: '待签署', // 待签署、已签署、已到期
        startDate: '2024-04-01',
        endDate: '2025-03-31',
        monthlyRent: 2800,
        deposit: 5600
      }
    })
  },

  // 获取账单信息
  getBillInfo() {
    // TODO: 调用账单API
    this.setData({
      billInfo: {
        currentBill: {
          id: 'BL2024001',
          month: '2024-03',
          rent: 2800,
          water: 85,
          electric: 156,
          total: 3041,
          status: '待支付'
        },
        billHistory: [
          {
            id: 'BL2024002',
            month: '2024-02',
            total: 3125,
            status: '已支付'
          }
        ]
      }
    })
  },

  // 获取物业公告
  getNotices() {
    // TODO: 调用公告API
    this.setData({
      notices: [
        {
          id: 1,
          title: '关于本周六进行消防演练的通知',
          date: '2024-03-15',
          type: '重要'
        },
        {
          id: 2,
          title: '小区电梯维护通知',
          date: '2024-03-14',
          type: '普通'
        }
      ]
    })
  },

  // 在线签约
  onSignContract() {
    wx.navigateTo({
      url: `/pages/house/contract/sign?id=${this.data.contractInfo.id}`
    })
  },

  // 在线支付
  onPayBill() {
    wx.navigateTo({
      url: `/pages/house/payment/payment?id=${this.data.billInfo.currentBill.id}`
    })
  },

  // 申请电子发票
  onRequestInvoice() {
    wx.navigateTo({
      url: `/pages/house/invoice/apply?billId=${this.data.billInfo.currentBill.id}`
    })
  }
}) 